
function mainmenu()
{
	showtheFinger = false;	//huh? finger?
	var img;
	curse.stop(); curse.play(false);
	var finger = LoadImage("thefinger.png");
	var yfin = 8, yfin2 = 8;
	var redraw = true;
	var mode = "main";
	var quit = false;

	do
	{
		if (redraw)
		{
			ApplyColorMask(Black);
			window.drawWindow(8,8,320-16, 240-16);
			window2.drawWindow(230+xbo, ybo, 95-xbo*2, 145-ybo*2);
			window2.drawWindow(230+xbo, 142+ybo, 95-2*xbo, 35-2*ybo);
			window2.drawWindow(210+xbo, 175+ybo, 115-2*xbo, 65-2*ybo);
			//alphagrad.transformBlit(5,5,  314,5,  314,234,  5,234);
			alphagrad.blit(0,0);
			for (var g=0; g<party.length; g++)
			{
				if (party[g] != undefined)
				{
					var mugshot = LoadImage( (charstats[party[g]].facepic) ? charstats[party[g]].facepic : "Face00.png");
					mugshot.blit(25,15+g*58);
					font2.setColorMask(Cyan);
					font2.drawText(70, 26+g*58, "LV");
					font2.drawText(70, 37+g*58, "HP");
					font2.drawText(70, 48+g*58, "MP");
					font2.setColorMask(White);
					font2.drawText(70, 15+g*58, charstats[party[g]].name);
					font2.drawText(90, 26+g*58, charstats[party[g]].level);
					font2.drawText(90, 37+g*58, charstats[party[g]].hp);
					font2.drawText(90, 48+g*58, charstats[party[g]].mp);
				}
			}
			/*
			window2.drawWindow(xbo*2, 15, 200-xbo*2, 35);
			window2.drawWindow(xbo*2, 73, 200-xbo*2, 35);
			window2.drawWindow(xbo*2, 131, 200-xbo*2, 35);
			window2.drawWindow(xbo*2, 190, 200-xbo*2, 35);
			*/
			font2.setColorMask(Cyan);
			font2.drawText(250, 148, "Time:");
			if (eventBox['prechase'].happened)
				font2.drawText(225, 185, "Evil Laughs:");
			font2.drawText(225,210, "GP:");
			font2.setColorMask(White);
			font2.drawText(255, 10, "Items");
			font2.drawText(255, 25, "Shards" );
			font2.drawText(255, 40, "Skills ");
			font2.drawText(255, 55, "Equip");
			font2.drawText(255, 70, "Relic");
			font2.drawText(255, 85, "Status");
			font2.drawText(255, 100, "Config");
			font2.drawText(255, 115, "Load");
			if (!saveable) font2.setColorMask(CreateColor(128,128,128,255));
			font2.drawText(255, 130, "Save");
				font2.setColorMask(CreateColor(255,255,255,255));
			if (eventBox['prechase'].happened)
				font2.drawText(240,197, evillaughs);
			font2.drawText(240,221, money);
			img = GrabImage(0,0,320,240);	//Graw BiMage
			redraw = false;
		}
	
		img.blit(0,0);
		font2.drawText(250, 159, timer.getTime());		
		if (mode != "main")
		{
			if (mode == "order2")
				finger.blitMask(10, yfin2, halfTint);
			else if (mode != "order")
				finger.blitMask(236, yfin2, halfTint);
		}
		finger.blit((mode=="main")?236:5, yfin);
		
		FlipScreen();
		
		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case KEY_DOWN:
			{
				if (mode=="main")
				{
					if (yfin < 128) yfin += 15;
					else yfin = 8;
				}
				else
				{
					if (yfin < 15+58*(party.length-1)) yfin += 58;
					else yfin = 15;
				}
				curse.stop(); curse.play(false);
				break;
			}
			case KEY_UP:
			{
				if (mode=="main")
				{
					if (yfin > 8) yfin -= 15;
					else yfin = 128;
				}
				else
				{
					if (yfin > 15) yfin -= 58;
					else yfin = 15+58*(party.length-1);
				}
				curse.stop(); curse.play(false);
				break;
			}
			case key_talk:
			{
				curse.stop(); curse.play(false);
				if (mode == "main")
				{
					if	  (yfin ==  8)  {redraw = true; item_menu(); yfin = 8;}
					else if (yfin == 23) { redraw = true; shard_menu();   yfin = 23;}
					else if (yfin == 38) { mode = "skill";   yfin = 15; yfin2 = 38;}
					else if (yfin == 53) { mode = "equip"; yfin = 15; yfin2 = 53;}
					else if (yfin == 68) { mode = "relic";   yfin = 15; yfin2 = 68;}
					else if (yfin == 83) { mode = "status"; yfin = 15; yfin2 = 83;}
					else if (yfin == 98) { config_menu(); yfin = 98; redraw=true;}
					else if (yfin == 113) { LoadGameMenu("load"); return;}
					else if (yfin == 128){ if (saveable || IsKeyPressed(KEY_SLASH)) LoadGameMenu("save"); }
					else;	//uh oh.
				}
				else if (mode=="equip")
				{
					equipmenu( (yfin-15) / 58);	//char relative to pointer
					mode = "main";
					yfin = 8;
				}
				else if (mode == "status")
				{
					statmenu( (yfin-15) / 58);
					mode = "main";
					yfin = 8;
				}
				else if (mode == "order")
				{
					mode = "order2";
					yfin2 = yfin;
					curse.stop(); curse.play(false);
					break;
				}
				else if (mode == "order2")
				{
					if (yfin != yfin2)
					{
						if (eventBox['furniture_mission'].inprog){ mode = "order"; break; }
						var ax_em = party[(yfin-15)/58];
						party[(yfin-15)/58] = party[(yfin2-15)/58];
						party[(yfin2-15)/58] = ax_em;
						if ((yfin-15)/58==0 || (yfin2-15)/58==0)	//changed PC
						{
							var xy=GetPersonX(thePC.name),yx=GetPersonY(thePC.name), lyr=GetPersonLayer(thePC.name);
							DestroyPerson(thePC.name);
							thePC = new retard(party[0], charstats[party[0]].rss, false);
							SetPersonX(thePC.name, xy);
							SetPersonY(thePC.name, yx);
							SetPersonLayer(thePC.name, lyr);
							people = GetPersonList();
							AttachInput(thePC.name);
							AttachCamera(thePC.name);
						}
						redraw = true;
					}
					mode = "order";
					curse.stop(); curse.play(false);	//maybe a sillier sound..
				}
				break;
			}
			case key_cancel:
			{
				if (mode != "main") {
					mode = "main";
					yfin = 8;
					if( (yfin2-8)%15 == 0 )
						yfin = yfin2;
				}
				else quit = true;
				curse.stop(); curse.play(false);
				idletime = GetTime();
				break;
			}
			case KEY_LEFT:
			{
				if (mode=="main")
				{
					yfin = 15;
					mode = "order";
					curse.stop(); curse.play(false);
				}
				break;
			}
			case KEY_RIGHT:
			{
				if (mode == "order")
				{
					yfin = 8;
					mode = "main";
					curse.stop(); curse.play(false);
				}
				break;
			}
		}
		}
		
	}while(!quit)

}



function item_menu()
{
	var beegee;
	var finger = LoadImage("thefinger.png");
	var xfin = 6, yfin = 0;
	var xfin2 = 10, yfin2 = 0;
	var xfin3 = 60;
	var loup = true;
	var framedraw = 0;
	var tempspot = "";
	var mode = "select1";
	var doit = true;
	var toppy = 0;
	var thelisto = new Array();
	//only display possessed items
	for (var r=0; r<itemlist.length; r++) 
		if (items[itemlist[r]].quantity>0)	thelisto[items[itemlist[r]].order] = itemlist[r];

	do
	{
		if (doit)
		{
			window.drawWindow(0,0,GetScreenWidth(), GetScreenHeight());
			alphagrad.blit(0,0);
			window2.drawWindow(xbo-2, ybo, 40, 10);
			window2.drawWindow(xbor*2+40, ybo, 220, 10);
			window2.drawWindow(xbor, 44, 300, 10);
			window2.drawWindow(xbor, 77, 300, 150);
			font2.drawText(70,12, "  USE     SORT     RARE");
			font2.setColorMask(Cyan);
			font2.drawText(10, 12, "Item");
			font2.setColorMask(White);
			Rectangle(302,70, 5, 165, CreateColor(255,255,255, 60));
			for (var d=0; d<13; d++)
			{
				if (items[thelisto[d+toppy]])													{	//whoa!!
				font2.drawText(25, 75+d*12, items[thelisto[d+toppy]].name);
				font2.drawText(220, 75+d*12, ": " + items[thelisto[d+toppy]].quantity);		}
			}
			beegee = GrabImage(0,0, 320, 240);
			doit = false;
		}
		
		beegee.blit(0,0);
		Rectangle(302,70+(toppy/287)*160,5,5, Cyan);
		if (mode != "mode_sel") { finger.blitMask(xfin3, 7, halfTint); }
		else finger.blit(xfin3, 7);
		if (mode == "select2")
		{
			if (yfin2-toppy >= 0) finger.blitMask(xfin2, (yfin2-toppy)*12+75, halfTint);
			finger.blit(3, yfin*12+75);
		}
		if (mode == "select1") finger.blit(3, yfin*12+75);
		framedraw++;
		font.drawText(17,42,yfin+toppy);
		
		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case key_cancel:
			{
				if (mode == "mode_sel")
				{ loup = false; curse.stop(); curse.play(false);}
				else if (mode == "select1")
				{mode = "mode_sel"; yfin = 0;}
				else if (mode == "select2")
				mode = "select1";
				break;
			}
			case KEY_DOWN:
			{
				if (mode=="select1" || mode=="select2")
				{
					if (yfin+toppy < 299)
					{
						if (yfin==12)
						{toppy++; doit = true;}
						else yfin++;
						curse.stop(); curse.play(false);
					}
				}
				break;
			}
			case KEY_UP:
			{
				if (mode=="select1" || mode=="select2")
				{
					if (yfin+toppy > 0)
					{
						if (yfin==0)
						{toppy--; doit = true;}
						else yfin--;
						curse.stop(); curse.play(false);
					}
				}
				break;
			}
			case KEY_RIGHT:
			{
				if (mode=="mode_sel")
				{
					if (xfin3==176)
					xfin3 = 60;
					else xfin3 += 58;
					curse.stop(); curse.play(false);
				}
				break;
			}
			case KEY_LEFT:
			{
				if (mode=="mode_sel")
				{
					if (xfin3==60)
					xfin3 = 176;
					else xfin3 -= 58;
					curse.stop(); curse.play(false);
				}
				break;
			}
			case key_talk:
			{
				if (mode == "mode_sel")
				{
					if (xfin3==60)
					mode = "select1";
					if (xfin3==60+58)
					mode = "select1";
					curse.stop(); curse.play(false);
				}
				else if (mode == "select1")
				{
					yfin2 = yfin+toppy;
					mode = "select2";
				}
				else if (mode == "select2")
				{
					if (yfin+toppy == yfin2)
					{
						if (thelisto[yfin+toppy] != undefined)
							applyMenu(thelisto[yfin+toppy]);
						//take out unpossessed items (after useage)
						for (var r=0; r<itemlist.length; r++)
							if (thelisto[r])
								if (items[thelisto[r]].quantity<1)
									thelisto[items[itemlist[r]].order] = undefined;
						mode = "select1";
						doit = true;
					}
					else
					{	//SWAP EM
						tempspot = thelisto[yfin+toppy];
						thelisto[yfin+toppy] = thelisto[yfin2];
						thelisto[yfin2] = tempspot;
						mode = "select1";
						doit = true;
					}
				}
				curse.stop(); curse.play(false);
				break;
			}
			case KEY_HOME:
			{
				yfin = 0;
				toppy = 0;
				doit = true;
				curse.stop(); curse.play(false);
				break;
			}
			case KEY_END:
			{
				toppy = 287;
				yfin = 12;
				doit = true;
				curse.stop(); curse.play(false);
				break;	
			}
			case KEY_PAGEUP:
			{
				break;
			}
			case KEY_PAGEDOWN:
			{
				break;
			}
		}
		}
		FlipScreen();
	} while (loup)						
	
	//change the REAL list
	for (var v=0; v<300; v++)
	{
		if (thelisto[v] != undefined)
		items[thelisto[v]].order = v;
	}
	//check for thievery
	for (var d=0; d<itemlist.length; d++)
	{
		for (var e=d+1; e<itemlist.length; e++)
		{
		if (items[itemlist[d]].order == items[itemlist[e]].order)
		{
			var victim = (items[itemlist[d]].quantity < 1) ? d : e;
			//put the victim in a blank
			for (var l=0; l<itemlist.length; l++)
			{
				if (thelisto[l] == undefined){
				items[itemlist[victim]].order = l;
				thelisto[l] = 1;	//defined!
				break;}
			}
		}
		}
	}
}

function shard_menu()
{
	var mugshot = LoadImage( (charstats[party[0]].facepic) ? charstats[party[0]].facepic : "Face00.png");
	var beegee;
	var finger = LoadImage("thefinger.png");
	var xfin = 6, yfin = -1;
	var xfin2 = 10, yfin2 = 0;
	var xfin3 = 70; yfin3 = 0;
	var yfin4 = 0;
	var loup = true;
	var framedraw = 0;
	var tempspot = "";
	var mode = "mode_sel";
	var doit = true;
	var toppy = 0;
	var actionmenu = 0;
	var rehash_list = true;
	var thelisto = new Array();
	charshards[2] = 99;
	charshards[6] = 3;
	charshards[21] = 1;
	charshards[39] = 2;

	// don't forget to make sure this spell list is the same as the one in battle.js
	var currshard = new Array();
	var i = 0;
	var spells = new Array();
	var xp = new Array();
	spells[i] = "|Fire  "; xp[i++]=10; spells[i] = "|Ice   "; xp[i++]=10; spells[i] = "|Bolt  "; xp[i++]=10;
	spells[i] = "|      "; xp[i++]=00; spells[i] = "|      "; xp[i++]=00; spells[i] = "|      "; xp[i++]=00;
	spells[i] = "|Fire2 "; xp[i++]=05; spells[i] = "|Ice2  "; xp[i++]=05; spells[i] = "|Bolt2 "; xp[i++]=05;
	spells[i] = "|      "; xp[i++]=00; spells[i] = "|      "; xp[i++]=00; spells[i] = "|      "; xp[i++]=00;
	spells[i] = "|Fire3 "; xp[i++]=02; spells[i] = "|Ice3  "; xp[i++]=02; spells[i] = "|Bolt3 "; xp[i++]=02;
	spells[i] = "|      "; xp[i++]=00; spells[i] = "|      "; xp[i++]=00; spells[i] = "|      "; xp[i++]=00;
	spells[i] = "|      "; xp[i++]=00; spells[i] = "|      "; xp[i++]=00; spells[i] = "|Ultima"; xp[i++]=01;

	spells[i] = "{Cure  "; xp[i++]=10; spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00;
	spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00;
	spells[i] = "{Cure2 "; xp[i++]=05; spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00;
	spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00;
	spells[i] = "{Cure3 "; xp[i++]=02; spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00;
	spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00; spells[i] = "{      "; xp[i++]=00;
	
	spells[i] = "}Scan  "; xp[i++]=15; spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00;
	spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00;
	spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00;
	spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00;
	spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00; spells[i] = "}      "; xp[i++]=00;
	spells[i] = "}      "; xp[i++]=00; spells[i] = "}X-Fer "; xp[i++]=04; spells[i] = "}      "; xp[i++]=00;
	
	
	do
	{
		if( rehash_list ) {
			thelisto = [];
			var x = 0;
			for (var r=0; r<charshards.length; r++) 
				if (charshards[r]>0)	thelisto[x++] = [r,charshards[r]];
			rehash_list = false;
			if( yfin >= thelisto.length )
				yfin = thelisto.length-1;
			if( mode == "select1" && thelisto.length == 0 )
				mode = "mode_sel";
		}
		if (doit)
		{
			window.drawWindow(0,0,GetScreenWidth(), GetScreenHeight());
			alphagrad.blit(0,0);
			window2.drawWindow(xbo-2, ybo, 40, 10);
			window2.drawWindow(xbor*2+40, ybo, 220, 10);
			window2.drawWindow(xbor, 44, 300, 10);
			window2.drawWindow(xbor, 77, 300, 150);
			window2.drawWindow(xbo-2,77,90,150);
			mugshot.blit(xbo+22, 85);

			for( var lol = 0; lol < 4; lol++ ) {
				font2.setColorMask(White);
				if( lol == yfin4 )
					font2.setColorMask(Cyan);
				if( party[lol] ) {
					font2.drawText(30, 136+24*lol, party[lol]);
					if( yfin != -1 ) {
						font2.drawText(40, 148+24*lol, charspells[party[lol]][thelisto[yfin+toppy][0]]+"%");
					}
				}
			}
			
			font2.setColorMask(White);
			font2.drawText(70,12, "   DUDES       SHARDS");
			font2.setColorMask(Cyan);
			font2.drawText(10, 12, "Shard");
			font2.setColorMask(White);
			Rectangle(302,70, 5, 165, CreateColor(255,255,255, 60));
			for (var d=0; d<thelisto.length && d<13; d++)
			{
				currshard = thelisto[d+toppy]
				if ( currshard[1] > 0 )	{
					font2.drawText(130, 75+d*12, spells[currshard[0]]);
					font2.drawText(180, 75+d*12, ": " + currshard[1] );	
					font2.drawText(230, 75+d*12, ": +" + xp[currshard[0]] + "%");
				}
			}
			if( mode == "action" ) {
				window.drawWindow( 160, actionmenu, 90, 50 );
				font2.drawText( 174, actionmenu+03, "Use" );
				font2.drawText( 174, actionmenu+15, "Throw One" );
				font2.drawText( 174, actionmenu+27, "Throw All" );
				font2.drawText( 174, actionmenu+39, "Cancel" );
			}
			beegee = GrabImage(0,0, 320, 240);
			doit = false;
		}
		
		beegee.blit(0,0);
		Rectangle(302,70+(toppy/spells.length)*160,5,40, Cyan);
		if (mode != "mode_sel") { finger.blitMask(xfin3, 7, halfTint); }
		else finger.blit(xfin3, 7);
		if (mode == "select1") finger.blit(110, yfin*12+75);
		else if( mode == "action" ) finger.blit(150, actionmenu + 3 + yfin3*12);
		else if( mode == "selectdude" ) finger.blit(15, 136+24*yfin4);
		framedraw++;
		if( yfin != -1 ) font.drawText(17,46,spells[thelisto[yfin+toppy][0]]);
		
		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case key_cancel:
			{
				if (mode == "mode_sel")
				{ loup = false; curse.stop(); curse.play(false);}
				else if (mode == "select1")
				{mode = "mode_sel"; yfin = -1;}
				else if (mode == "selectdude")
				mode = "mode_sel";
				else if (mode == "action") {
					yfin3 = 0;
					mode = "select1";
				}
				doit = true;
				break;
			}
			case KEY_DOWN:
			{
				if (mode=="select1")
				{
					if (yfin+toppy < thelisto.length-1)
					{
						if (yfin==12)
							toppy++;
						else
							yfin++;
						doit = true;
						curse.stop(); curse.play(false);
					}
				}
				if ( mode == "action") {	
				  // move the pointer one down, looping to the start if needbe				
					yfin3 = (yfin3 + 5) % 4;
					doit = true;
				}
				if( mode == "selectdude" ) {
					// move the pointer one down, looping to the start if needbe
					yfin4 = (yfin4 + party.length + 1) % party.length;
					mugshot = LoadImage( (charstats[party[yfin4]].facepic) ? charstats[party[yfin4]].facepic : "Face00.png");
					curse.stop(); curse.play(false);
					doit = true;
				}
				break;
			}
			case KEY_UP:
			{
				if (mode=="select1")
				{
					if (yfin+toppy > 0)
					{
						if (yfin==0)
							toppy--;
						else
							yfin--;
						doit = true;
						curse.stop(); curse.play(false);
					}
				}
				if ( mode == "action") {
					// move the pointer one up, looping to the end if needbe
					yfin3 = (yfin3 + 3) % 4;
					curse.stop(); curse.play(false);
					doit = true;
				}
				if( mode == "selectdude" ) {
					// move the pointer one up, looping to the end if needbe
					yfin4 = (yfin4 + party.length - 1) % party.length;
					mugshot = LoadImage( (charstats[party[yfin4]].facepic) ? charstats[party[yfin4]].facepic : "Face00.png");
					doit = true;
				}				
				break;
			}
			case KEY_RIGHT:
			{
				if (mode=="mode_sel")
				{
					xfin3 = 150;
					curse.stop(); curse.play(false);
				}
				break;
			}
			case KEY_LEFT:
			{
				if (mode=="mode_sel")
				{
					xfin3 = 70;
					curse.stop(); curse.play(false);
				}
				break;
			}
			case key_talk:
			{
				if (mode == "mode_sel")
				{
					if (xfin3==150 && thelisto.length > 0) {
						mode = "select1";
						if( yfin == -1 )
							yfin = 0;
					}
					if (xfin3==70)
					mode = "selectdude";
					curse.stop(); curse.play(false);
					doit = 1;
				}
				else if (mode == "select1")
				{
					mode = "action";
					actionmenu = 80 + (yfin>8?8:yfin)*12;
					doit = true;
				}
				else if ( mode == "action" ) {
					switch( yfin3 ) {
						case 0: // use
						{
							currshard = thelisto[yfin+toppy];			
							if( charspells[party[yfin4]][currshard[0]] >= 100 )
								break;
							if( confirm_action("Really use a "+spells[currshard[0]]+" shard on "+party[yfin4]+"?") ) {
								charshards[currshard[0]]--;
								charspells[party[yfin4]][currshard[0]] = parseInt( charspells[party[yfin4]][currshard[0]] + xp[currshard[0]] );
								// this fixes a weird bug
								if( charspells[party[yfin4]][currshard[0]] < xp[currshard[0]] )
									charspells[party[yfin4]][currshard[0]] = parseInt(xp[currshard[0]]);
								if( charspells[party[yfin4]][currshard[0]] > 100 )
									charspells[party[yfin4]][currshard[0]] = 100;
								rehash_list = true;
								doit = true;
								mode = "select1";
							}
							doit = true;
							break;
						}
						case 1: // junk one
						{
							currshard = thelisto[yfin+toppy];			
							var message = "Really junk 1 of "+currshard[1]+" "+spells[currshard[0]]+" shards?";
							if( currshard[1]-1 == 0 )
								message = "Really junk your last "+spells[currshard[0]]+" shard?";
							if( confirm_action(message) ) {
								charshards[currshard[0]]--;
								rehash_list = true;
								doit = true;
								mode = "select1";
							}
							doit = true;
							break;
						}
						case 2: // junk all
						{
							currshard = thelisto[yfin+toppy];							
							if( confirm_action("Really junk all "+currshard[1]+" "+spells[currshard[0]]+" shards?") ) {
								charshards[currshard[0]] = 0;
								rehash_list = true;
								doit = true;
								mode = "select1";
							}
							doit = true;
							break;
						}
						case 3: // cancel
						{
							mode = "select1";
							yfin3 = 0;
							doit = true;
							break;
						}
					}
				}
				curse.stop(); curse.play(false);
				break;
			}
			case KEY_HOME:
			{
				if( mode == "select1" ) {
					yfin = 0;
					toppy = 0;
					doit = true;
					curse.stop(); curse.play(false);
				}
				break;
			}
			case KEY_END:
			{
				if( mode == "select1" ) {
					toppy = thelisto.length-13;
					yfin = 12;
					if( toppy < 0 ) {
						toppy = 0;
						yfin = 12;
						if( yfin >= thelisto.length ) {
							yfin = thelisto.length-1;
							toppy = 0;
						}
					}
					doit = true;
					curse.stop(); curse.play(false);
				}
				break;	
			}
			case KEY_PAGEUP:
			{
				if( mode == "select1" ) {
					toppy -= 13;
					if( toppy < 0 ) {
						toppy = 0;
						yfin = 0;
					}
					doit = true;
				}
				break;
			}			
			case KEY_PAGEDOWN:
			{
				if( mode == "select1" ) {
					toppy += 13;
					if( toppy > thelisto.length-13 ) {
						toppy = thelisto.length-13; 
						yfin = 12;
						if( yfin >= thelisto.length ) {
							yfin = thelisto.length-1;
							toppy = 0;
						}
					}
					doit = true;
				}
				break;
			}
		}
		}
		FlipScreen();
	}	while(loup);
}

function confirm_action(message)
{
	var selection = false;
	var selected = false;
	var finger = LoadImage("thefinger.png");
	
	do
	{
		window.drawWindow(10,100,300,40);
		font2.setColorMask(White);
		font2.drawText(20,  105, message);
		font2.drawText(100,  120, "Yes");
		font2.drawText(160, 120, "No");
		finger.blit( selection==true ? 82 : 142, 120);
		if (AreKeysLeft()) {
			switch( GetKey() ) {
				case KEY_LEFT:
				{
					selection = true;
					redraw = true;
					break;
				}
				case KEY_RIGHT:
				{
					selection = false;
					redraw = true;
					break;
				}
				case key_talk:
				{
					selected = true;
					break;
				}
				case key_cancel:
				{
					selection = false;
					selected = true;
					break;
				}
			}
		}
		FlipScreen();
	} while( selected == false );
	
	return selection;	
}

function finditem(f)
{
	for (var n=0; n<itemlist.length; n++)
		if (items[itemlist[n]].order==f)
		return n;
	return 299;	//BAD!!
}


function applyMenu(item)
{
	curse.stop(); curse.play(false);
	var crackmonster =GrabImage(0,0,320,240);
	var dudes = [];
	for (var bigot=0; bigot<party.length; bigot++)
		dudes[bigot] = LoadSpriteset(charstats[party[bigot]].rss);
	//determine poses
	var deadposes = [];
	var weakposes = [];
	var normposes = [];
	var gayposes = [];
	for (var lame=0; lame<party.length; lame++)
	{
			var thelife = dudes[lame].directions;
			for (var shame=0; shame<thelife.length; shame++)
			{
				if (thelife[shame].name == "down1")
					deadposes[lame] = dudes[lame].images[ thelife[shame].frames[0].index ];
				if (thelife[shame].name == "crouch")
					weakposes[lame] = dudes[lame].images[ thelife[shame].frames[0].index ];
				if (thelife[shame].name == "south")
					normposes[lame] = dudes[lame].images[ thelife[shame].frames[0].index ];
			}
	}
	for (var v=0; v<party.length; v++)
	{	//place-holding imgs for undefined
		if (!deadposes[g]) deadposes[g] = pointer;
		if (!weakposes[g]) weakposes[g] = pointer;
		if (!normposes[g]) normposes[g] = pointer;
	}
	
	if (fanceydisplay)
	{
		var timey = GetTime();
		for (var KKK=0; KKK<20; KKK++)
		{
			crackmonster.blit(0,0);
			window.drawWindow(xbor+5, (ybor-20) + KKK, 125, 30);
			alphagrad.transformBlit( xbor+5-rfXo,		ybor-20+KKK-rfYo,
									xbor+5+125+rfXo,	ybor-20+KKK-rfYo,
									xbor+5+125+rfXo,	ybor-20+KKK+30+rfYo,
									xbor+5-rfXo,		ybor-20+KKK+30+rfYo
									);
			font.drawTextBox(xbor+7, (ybor-17) + KKK, 125, 30, 0, items[item].name + ":\n\t\t\t" + items[item].quantity);
			window.drawWindow(320-KKK*8, ybor, 125, 240-ybor*2);
			alphagrad.transformBlit(	320-KKK*8-rfXo,		ybor-rfYo,
									320-KKK*8+125+rfXo,	ybor-rfYo,
									320-KKK*8+125+rfXo,	240-ybor+rfYo,
									320-KKK*8-rfXo, 		240-ybor+rfYo
									);
			for (var g=0; g<party.length; g++)
			{
				if (party[g] != undefined)
				{
					if (charstats[party[g]].hp < 1)
						deadposes[g].blit(320-KKK*8+75, 10+g*58);
					else if (charstats[party[g]].hp < charstats[party[g]].hp_max*.15)
						weakposes[g].blit(320-KKK*8+75, 10+g*58);
					else normposes[g].blit(320-KKK*8+75, 10+g*58);
					font2.setColorMask(Cyan);
					font2.drawText(320-KKK*8 + 15, 37+g*58, "HP");
					font2.drawText(320-KKK*8 + 15, 48+g*58, "MP");
					font2.setColorMask(White);
					font2.drawText(320-KKK*8 + 5, 15+g*58, charstats[party[g]].name);
					font2.drawText(320-KKK*8 + 35, 37+g*58, charstats[party[g]].hp + "/" + charstats[party[g]].hp_max);
					//critical COLOR
					if (charstats[party[g]].hp < charstats[party[g]].hp_max*.15)
					{
						font2.setColorMask(Red);
						font2.drawText(320-KKK*8 + 35, 37+g*58, charstats[party[g]].hp);
						font2.setColorMask(White);
					}
					font2.drawText(320-KKK*8 + 35, 48+g*58, charstats[party[g]].mp + "/" + charstats[party[g]].mp_max);
				}
			}
			FlipScreen();
			while (GetTime() - timey < 20);	//FPS LIMIT
			timey = GetTime();
		}
	}
	
	var etern = true;
	var redraw = true;
	var flingaY=0;
	var success = 0;
	
	while (etern)
	{
		if (redraw)
		{
			crackmonster.blit(0,0);
			window.drawWindow(xbor+5, ybor, 125, 30);
			alphagrad.transformBlit( xbor+5-rfXo,		ybor-rfYo,
									xbor+5+125+rfXo,	ybor-rfYo,
									xbor+5+125+rfXo,	ybor+30+rfYo,
									xbor+5-rfXo,		ybor+30+rfYo
									);
			font.drawTextBox(xbor+7, ybor+2, 125, 30, 0, items[item].name + ":\n\t\t\t" + items[item].quantity);
			window.drawWindow(168, ybor, 125, 240-ybor*2);
			alphagrad.transformBlit(	168-rfXo,		ybor-rfYo,
									168+125+rfXo,	ybor-rfYo,
									168+125+rfXo,	240-ybor+rfYo,
									168-rfXo, 		240-ybor+rfYo
									);
			for (var g=0; g<party.length; g++)
			{
				if (party[g] != undefined)
				{
					if (charstats[party[g]].hp < 1)
						deadposes[g].blit(168+75, 10+g*58);
					else if (charstats[party[g]].hp < charstats[party[g]].hp_max*.15)
						weakposes[g].blit(168+75, 10+g*58);
					else normposes[g].blit(168+75, 10+g*58);
					font2.setColorMask(Cyan);
					font2.drawText(168 + 15, 37+g*58, "HP");
					font2.drawText(168 + 15, 48+g*58, "MP");
					font2.setColorMask(White);
					font2.drawText(168 + 5, 15+g*58, charstats[party[g]].name);
					font2.drawText(168 + 35, 37+g*58, charstats[party[g]].hp + "/" + charstats[party[g]].hp_max);
					//critical COLOR
					if (charstats[party[g]].hp < charstats[party[g]].hp_max*.15)
					{
						font2.setColorMask(Red);
						font2.drawText(168 + 35, 37+g*58, charstats[party[g]].hp);
						font2.setColorMask(White);
					}
					font2.drawText(168 + 35, 48+g*58, charstats[party[g]].mp + "/" + charstats[party[g]].mp_max);
				}
			}
			crackmonster = GrabImage(0,0,320,240);
			redraw = false;
		}
		crackmonster.blit(0,0);
		pointer.blit(160, 15+flingaY*58);
		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case KEY_UP:
			{
				flingaY--;
				if (flingaY < 0) flingaY = party.length-1;
				curse.stop(); curse.play(false);
				break;
			}
			case KEY_DOWN:
			{
				flingaY++;
				if (flingaY == party.length) flingaY = 0;
				curse.stop(); curse.play(false);
				break;
			}
			case key_cancel:
			{
				etern=false;
				break;
			}
			case key_talk:
			{
				success = USE_ITEM(item, party[flingaY]);
				if (typeof success != "number")
				{
					//junk is centered!!						
					window.drawWindow(GetScreenWidth()/2-font.getStringWidth(success)/2-15, 100+ybo, 
										font.getStringWidth(success)+30, 10);
					alphagrad.transformBlit
					(
						GetScreenWidth()/2- font.getStringWidth(success)/2-15-rfXo,		100+ybo-rfYo,
						GetScreenWidth()/2+font.getStringWidth(success)/2+15+rfXo,	100+ybo-rfYo,
						GetScreenWidth()/2+font.getStringWidth(success)/2+15+rfXo,	100+ybo+10+rfYo,
						GetScreenWidth()/2- font.getStringWidth(success)/2-15-rfXo,		100+ybo+10+rfYo
					);				
					font.drawText(GetScreenWidth()/2 - font.getStringWidth(success)/2, 100+ybo, success);
					//EH EHHH!! sfx
					FlipScreen();
					GetKey();
				}
				success = 0;
				redraw = true;
				if (items[item].quantity < 1) etern = false;
				break;
			}
		}
		}
		FlipScreen();
	}
}

function config_menu()
{
	var neverstop = true;
	var fingre = LoadImage("thefinger.png");
	var FX=5, FY=38;
	var whichmode = "norm";
	var redrawl = true;
	var rapidCB = false;
	var framedraw = 0;
	var colorit = false;
	var beegee;
	var keyz = new Array();
	keyz[1] = "ESC";
	keyz[2] = "F1";
	keyz[3] = "F2";
	keyz[4] = "F3";
	keyz[5] = "F4";
	keyz[27] = "BACKSP";
	keyz[28] = "TAB";
	keyz[55] = "SHIFT";
	keyz[58] = "SPACE";
	keyz[67] = "ENTER";
	keyz[68] = "INSERT";
	keyz[69] = "DELETE";
	keyz[70] = "HOME";
	keyz[71] = "END";
	keyz[72] = "PAGE_U";
	keyz[73] = "PAGE_D";
	
	var temp_talk = key_talk;
	var temp_cancel = key_cancel;
	var temp_shoes = key_shoes;
	var temp_debug = key_debug;
	var temp_laugh = key_laugh;
	var temp_menu = key_menu;
	
	var fpsedit = 0;
	
	var winlist = GetFileList("windowstyles");
	
	do
	{
		if (redrawl)
		{
			window.drawWindow(0,0,GetScreenWidth(), GetScreenHeight());
			alphagrad.blit(0,0);
			window2.drawWindow(xbo, ybo+2, 320-xbo*2, 4);
			font2.drawText(320/2-font2.getStringWidth("gifnoC")/2,10, "Config");
			window2.drawWindow(xbo, 40, 320-xbo*2, 150);
			font2.drawText(25, 38, "Redefine Input");
			font2.drawText(25, 38+font.getHeight(), "Fancey Display: "+((fanceydisplay)?"ON":"OFF"));
			font2.drawText(25, 38+font.getHeight()*2, "Window Style");
			font2.drawText(25, 38+font.getHeight()*3, "Frames Per Second: " + GetMapEngineFrameRate());
			if (whichmode == "inputting_choose" || whichmode == "inputting_key")
			{
				window.drawWindow(140,38+ybo,170,65);
				font2.drawText(155, 38+ybo, "Talk/Confirm:");
				font2.drawText(155, 38+ybo+font2.getHeight(), "Back/Cancel:");
				font2.drawText(155, 38+ybo+font2.getHeight()*2, "Menu:");
				font2.drawText(155, 38+ybo+font2.getHeight()*3, "Laugh Crazy:");
				font2.drawText(155, 38+ybo+font2.getHeight()*4, "Debug Room:");
				font2.drawText(155, 38+ybo+font2.getHeight()*5, "Sprint Shoes:");
				
				if (colorit){ if (FY==38+ybo) font2.setColorMask(Cyan); else font2.setColorMask(White); }
				font2.drawText(255, 38+ybo, (GetKeyString(temp_talk,false)==("" | " ")) ? keyz[temp_talk] : GetKeyString(temp_talk,true));
				
				if (colorit){ if (FY==38+ybo+font2.getHeight()) font2.setColorMask(Cyan); else font2.setColorMask(White);}
				font2.drawText(255, 38+ybo+font2.getHeight(), (GetKeyString(temp_cancel,false)==("" | " ")) ? keyz[temp_cancel] : GetKeyString(temp_cancel,true));
				
				if (colorit){ if (FY==38+ybo+font2.getHeight()*2)  font2.setColorMask(Cyan); else font2.setColorMask(White);}
				font2.drawText(255, 38+ybo+font2.getHeight()*2, (GetKeyString(temp_menu,false)==("" | " ")) ? keyz[temp_menu] : GetKeyString(temp_menu,true));
				
				if (colorit){ if (FY==38+ybo+font2.getHeight()*3)  font2.setColorMask(Cyan); else font2.setColorMask(White);}
				font2.drawText(255, 38+ybo+font2.getHeight()*3, (GetKeyString(temp_laugh,false)==("" | " ")) ? keyz[temp_laugh] : GetKeyString(temp_laugh,true));
				
				if (colorit){ if (FY==38+ybo+font2.getHeight()*4)  font2.setColorMask(Cyan); else font2.setColorMask(White);}
				font2.drawText(255, 38+ybo+font2.getHeight()*4, (GetKeyString(temp_debug,false)==("" | " ")) ? keyz[temp_debug] : GetKeyString(temp_debug,true));
				
				if (colorit){ if (FY==38+ybo+font2.getHeight()*5)  font2.setColorMask(Cyan); else font2.setColorMask(White);}
				font2.drawText(255, 38+ybo+font2.getHeight()*5, (GetKeyString(temp_shoes,false)==("" | " ")) ? keyz[temp_shoes] : GetKeyString(temp_shoes,true));
				
				font2.setColorMask(White);
			}
			beegee = GrabImage(0,0, GetScreenWidth(), GetScreenHeight());
			redrawl = false;
		}
		
		beegee.blit(0,0);

		if (whichmode=="inputting_key")
		{	var slam=GetKey();
			while (GetKeyString(slam,false) == "" && keyz[slam]==undefined) slam = GetKey();
			if (FY==38+ybo){ temp_talk = slam; redrawl = true;}
			if (FY==38+ybo+font2.getHeight()){ temp_cancel = slam; redrawl = true;}
			if (FY==38+ybo+font2.getHeight()*2){ temp_menu = slam; redrawl = true;}
			if (FY==38+ybo+font2.getHeight()*3){ temp_laugh = slam; redrawl = true;}
			if (FY==38+ybo+font2.getHeight()*4){ temp_debug = slam; redrawl = true;}
			if (FY==38+ybo+font2.getHeight()*5){ temp_shoes = slam; redrawl = true;}
			whichmode = "inputting_choose";
			colorit=false;
		}
		
		if (whichmode == "window_choose")
		{
			window.drawWindow(25, 50, 250, 130);
			for (var b=0; b<winlist.length; b++)
				font2.drawText(30,55+b*font.getHeight(), winlist[b]);
		}
		
		if (whichmode == "fpschoose")
		{
			font2.setColorMask(Cyan);
			font2.drawText(200, 38+font.getHeight()*3, GetMapEngineFrameRate() + fpsedit);
			font2.setColorMask(White);
		}
		
		//if (rapidCB) if (framedraw % 5 != 0){ fingre.blit(FX, FY); framedraw++; }
		fingre.blit(FX, FY);
		FlipScreen();
	
		
		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case key_cancel:
			{
				if (whichmode == "inputting_choose" || whichmode == "inputting_key")
				{
					var air = false;
					var temps = new Array(temp_talk, temp_cancel, temp_menu, temp_laugh, temp_debug, temp_shoes);
					for (o=0; o<7; o++)
						for (i=0; i<7; i++)
							if (i!=o) { if (temps[i]==temps[o]) air=true; }
							//checks whether functions have a common key
					if (!air)
					{
						whichmode="norm";
						rapidCB=false;
						FX=5;
						FY=38;
						redrawl=true;
						key_talk = temp_talk;
						SetTalkActivationKey(key_talk);
						key_cancel = temp_cancel;
						key_shoes = temp_shoes;
						key_debug =temp_debug ;
						key_laugh = temp_laugh;
						key_menu = temp_menu;
					}
					else
					{
						temp_talk = key_talk;
						temp_cancel = key_cancel;
						temp_shoes = key_shoes;
						temp_debug = key_debug;
						temp_laugh = key_laugh;
						temp_menu = key_menu;
						redrawl = true;
						FlipScreen();
						font.drawText(20,50,"Try again, smartass.");
						FlipScreen();
						GetKey();
					}
				}
				else if (whichmode=="window_choose")
				{
					whichmode = "norm";
					FX = 5;
					FY = 38+font.getHeight()*2;
				}
				else if (whichmode == "fpschoose")
				{
					whichmode = "norm";
					fpsedit = 0;
				}
				else neverstop = false;
				curse.stop(); curse.play(false);
				break;
			}
			case key_talk:
			{
				if (whichmode=="norm")
				{
					if (FY == 38){ whichmode="inputting_choose"; FX = 140; FY=38+ybo; redrawl=true; rapidCB=true;}
					else if (FY == 38+font.getHeight()) {fanceydisplay = !fanceydisplay; redrawl=true; }
					else if (FY == 38+font.getHeight()*2){ whichmode="window_choose"; FY = 55; FX = 10;}
					else if (FY == 38+font.getHeight()*3){ whichmode="fpschoose"; }
				}
				else if (whichmode=="inputting_choose")
				{
					colorit = true;
					redrawl = true;
					whichmode = "inputting_key";
				}
				else if (whichmode=="window_choose")
				{
					windowstyle = winlist[(FY-55)/font.getHeight()];
					window = LoadWindowStyle(windowstyle);
					redrawl=true;
				}
				else if (whichmode=="fpschoose")
				{
					fpschoice = GetMapEngineFrameRate() + fpsedit;
					SetMapEngineFrameRate(fpschoice);
					fpsedit = 0;
					whichmode = "norm";
					redrawl = true;
				}
				break;
			}
			case KEY_DOWN:
			{
				if (whichmode=="norm")
				{
					if (FY==38+font.getHeight()*3) FY = 38;	//update when more are added
					else FY += font.getHeight();
				}
				else if (whichmode=="inputting_choose")
					if (FY!=38+ybo+font2.getHeight()*5) FY+=font.getHeight();
					else;

				else if (whichmode=="window_choose")
					if (FY!=55+font.getHeight()*winlist.length) FY+=font.getHeight();
					else;
				else if (whichmode == "fpschoose")
					fpsedit--;

				break;
			}
			case KEY_UP:
			{
				if (whichmode=="norm")
				{
					if (FY==38) FY = 38+font.getHeight()*3;
					else FY -= font.getHeight();
				}
				else if (whichmode=="inputting_choose")
					if (FY!=38+ybo) FY-=font.getHeight();
					else;

				else if (whichmode=="window_choose")
					if (FY!=55) FY-=font.getHeight();
					else;
				else if (whichmode=="fpschoose");
					fpsedit++;

				break;
			}
		}
		}
		
	} while (neverstop)
	
}
	
function statmenu(whom)
{
	window.drawWindow(0,0,320,240);
	alphagrad.blit(0,0);
	window2.drawWindow(xbo,ybo,50,4);
	font.setColorMask(Cyan);
	font.drawText(xbo+5,9, "Status");
	font.drawText(55,55, "LV");
	font.drawText(55,65, "HP");
	font.drawText(55,75, "MP");
	font.drawText(15, 105, "Your Exp:");
	font.drawText(15, 125, "For Level Up:");
	font.drawText(20, 155, "Vigor");
	font.drawText(20, 165, "Speed");
	font.drawText(20, 175, "Stamina");
	font.drawText(20, 185, "Mag.Pwr");
	font.drawText(150, 145, "Bat.Pwr");
	font.drawText(150, 155, "Defense");
	font.drawText(150, 165, "Evade %");
	font.drawText(150, 175, "Mag.Def");
	font.drawText(150, 185, "MBlock %");
	
	font.setColorMask(White);
	font.drawText(15, 40, charstats[party[whom]].name);
	LoadImage(charstats[party[whom]].facepic).blit(15, 55);
	var grame = GrabImage(0,0,320,240);
	var jewitt = true;
	
	if (fanceydisplay)
	{
		var temp;
		var rate;
		var upcnt = 0;
		var watch;
		var watch2;
		do
		{
			watch = GetTime();
			grame.blit(0,0);
			
			temp = Math.round(charstats[party[whom]].exp * ((upcnt*50) / 1500));
			font.drawText(135 - font.getStringWidth(temp), 115, temp);
			
			font.drawText(135 - font.getStringWidth("??"), 135, "??");
			
			temp = Math.round(charstats[party[whom]].vigor * ((upcnt*50) / 1500));
			font.drawText(135 - font.getStringWidth(temp), 155, temp);
			
			temp = Math.round(charstats[party[whom]].speed * ((upcnt*50) / 1500));
			font.drawText(135 - font.getStringWidth(temp), 165, temp);
			
			temp = Math.round(charstats[party[whom]].stamina * ((upcnt*50) / 1500));
			font.drawText(135 - font.getStringWidth(temp), 175, temp);
			
			temp = Math.round(charstats[party[whom]].magpow * ((upcnt*50) / 1500));
			font.drawText(135 - font.getStringWidth(temp), 185, temp);
			
			temp = Math.round(charstats[party[whom]].batpow * ((upcnt*50) / 1500));
			font.drawText(250 - font.getStringWidth(temp), 145, temp);
			
			temp = Math.round(charstats[party[whom]].defense * ((upcnt*50) / 1500));
			font.drawText(250 - font.getStringWidth(temp), 155, temp);
			
			temp = Math.round(charstats[party[whom]].evade * ((upcnt*50) / 1500));
			font.drawText(250 - font.getStringWidth(temp), 165, temp+" %");
			
			temp = Math.round(charstats[party[whom]].magdef * ((upcnt*50) / 1500));
			font.drawText(250 - font.getStringWidth(temp), 175, temp);
			
			temp = Math.round(charstats[party[whom]].mblock * ((upcnt*50) / 1500));
			font.drawText(250 - font.getStringWidth(temp), 185, temp+" %");
			
			FlipScreen();
			upcnt++;
			if (AreKeysLeft()){ switch (GetKey())	//yeup.
			{
				case key_cancel:{ jewitt = false; curse.stop(); curse.play(false); break;}
				case KEY_PAGEUP:{ curse.stop(); curse.play(false); if (whom==party.length-1) statmenu(0); else statmenu(whom+1); return;}
				case KEY_PAGEDOWN:{ curse.stop(); curse.play(false); if (whom==0) statmenu(party.length-1); else statmenu(whom-1); return;}
			}}
			watch2 = GetTime();
			rate = watch2 - watch;
			if (rate < 50)	while (GetTime() < watch2+(50-rate));	// 50 ms/fr
		}
		while (Math.round(1500 / (GetTime() - watch)) > upcnt-1 && jewitt)	//for 1.5 s
	}	
		grame.blit(0,0);
		font.drawText(135 - font.getStringWidth(charstats[party[whom]].exp), 115, charstats[party[whom]].exp);
		font.drawText(135 - font.getStringWidth("??"), 135, "??");
		font.drawText(135 - font.getStringWidth(charstats[party[whom]].vigor), 155, charstats[party[whom]].vigor);
		font.drawText(135 - font.getStringWidth(charstats[party[whom]].speed), 165, charstats[party[whom]].speed);
		font.drawText(135 - font.getStringWidth(charstats[party[whom]].stamina), 175, charstats[party[whom]].stamina);
		font.drawText(135 - font.getStringWidth(charstats[party[whom]].magpow), 185, charstats[party[whom]].magpow);
		font.drawText(250 - font.getStringWidth(charstats[party[whom]].batpow), 145, charstats[party[whom]].batpow);
		font.drawText(250 - font.getStringWidth(charstats[party[whom]].defense), 155, charstats[party[whom]].defense);
		font.drawText(250 - font.getStringWidth(charstats[party[whom]].evade), 165, charstats[party[whom]].evade+" %");
		font.drawText(250 - font.getStringWidth(charstats[party[whom]].magdef), 175, charstats[party[whom]].magdef);
		font.drawText(250 - font.getStringWidth(charstats[party[whom]].mblock), 185, charstats[party[whom]].mblock+" %");

	grame = GrabImage(0,0,320,240);

	while (jewitt)
	{
		grame.blit(0,0);
		FlipScreen();
		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case key_cancel:{ jewitt = false; curse.stop(); curse.play(false); break;}
			case KEY_PAGEUP:{ curse.stop(); curse.play(false);  if (whom==party.length-1) statmenu(0); else statmenu(whom+1); return;}
			case KEY_PAGEDOWN:{ curse.stop(); curse.play(false); if (whom==0) statmenu(party.length-1); else statmenu(whom-1); return;}
		}
		}
	}
}


function equipmenu(fool)
{
	window.drawWindow(0,0,320, 240);
	alphagrad.blit(0,0);
	window2.drawWindow(xbo,ybo,320-xbo*2, 10);
	window2.drawWindow(xbo, 10+ybo*3, 320-xbo*2, 50);
	window2.drawWindow(xbo, 60+ybo*5, 320-xbo*2, 114);
	font.drawText(10,11, "   EQUIP       OPTIMUM    REMOVE     EMPTY");
	var vidiot = LoadSpriteset(charstats[party[fool]].rss);
	var vidirs = new Array();
	var vidiotsdir = 0;
	for (var g=0; g<vidiot.directions.length; g++)
	{
		if (vidiot.directions[g].name=="south") vidirs[0] = vidiot.directions[g].frames[0].index;
		if (vidiot.directions[g].name=="anger") vidirs[1] = vidiot.directions[g].frames[0].index;
		if (vidiot.directions[g].name=="shock") vidirs[2] = vidiot.directions[g].frames[0].index;
	}
	font.setColorMask(Cyan);
	font.drawText(15, 43, "R-Hand");
	font.drawText(15, 56, "L-Hand");
	font.drawText(15, 69, "Head");
	font.drawText(15, 82, "Body");
	font.drawText(180, 116, "Vigor");
	font.drawText(180, 129, "Speed");
	font.drawText(180, 142, "Stamina");
	font.drawText(180, 155, "Mag.Pwr");
	font.drawText(180, 168, "Bat.Pwr");
	font.drawText(180, 181, "Defense");
	font.drawText(180, 194, "Evade %");
	font.drawText(180, 207, "Mag.Def");
	font.drawText(180, 220, "MBlock%");
	for (var v=0; v<9; v++) font.drawText(275, 116+v*13, ">")
	font.setColorMask(White);
	for (var u=0; u<9; u++)
	font.drawText(275-font.getStringWidth(charstats[party[fool]][statlist[u+6]]), 116+13*u, charstats[party[fool]][statlist[u+6]]);
	
	font.drawText(245-font.getStringWidth(charstats[party[fool]].name)/2+16, 85, charstats[party[fool]].name);
	var stuff = GrabImage(0,0,320,240);
	var grawandstuff = true;
	var themode = "topmode";
	var finga = LoadImage("thefinger.png");
	var xFin=8, yFin=8;
	var mX, hY;
	var top_sel = 0, sel = 0;
	while (AreKeysLeft()) GetKey();
	
	while (grawandstuff)
	{
		stuff.blit(0,0);
		if (charstats[party[fool]].rhand) font.drawText(70, 43, weapons[charstats[party[fool]].rhand].name);
		if (charstats[party[fool]].lhand) font.drawText(70, 56, weapons[charstats[party[fool]].lhand].name);
		if (charstats[party[fool]].head) font.drawText(70, 69, weapons[charstats[party[fool]].head].name);
		if (charstats[party[fool]].body) font.drawText(70, 82, weapons[charstats[party[fool]].body].name);
		vidiot.images[vidirs[vidiotsdir]].blit(245, 50);
		finga.blit(xFin, yFin);
		if (themode=="equip_sel")
		{
			finga.blitMask(0, hY, halfTint);
			for (var f=top_sel; f<9; f++)
				if (weapons[weaponlist[f]]) font.drawText(15, 116+13*f, weapons[weaponlist[f]].name);
		}
		if (themode != "topmode") finga.blitMask(mX, 8, halfTint);
		FlipScreen();
		
		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case key_talk:
			{
				if (themode == "topmode")
				{
						if (xFin==8){ themode = "equip"; xFin=0; yFin = 43;  mX=8;}
					else if (xFin==88){ curse.stop(); curse.play(false); mX=88;}//optimize(fool); }
					else if (xFin==168){ themode = "remove"; xFin=0; yFin = 43; mX=168; }
					else if (xFin==248){ emptyequip(fool); }
				}
				else if (themode == "equip"){ themode="equip_sel"; xFin=0; hY=yFin; yFin=116; }
				else if (themode== "remove") charstats[party[fool]][statlist[17+ (yFin-43)/13]] = undefined;
				curse.stop(); curse.play(false);
				break;
			}
			case key_cancel:
			{
				if (themode=="topmode") grawandstuff = false;
				else if (themode=="equip" || themode=="remove"){ themode = "topmode"; xFin=8; yFin=8;}
				else if (themode=="equip_sel"){ themode="equip"; xFin=0; yFin=43; }
				curse.stop(); curse.play(false);
				break;
			}
			case KEY_RIGHT:
			{
				if (themode=="topmode")
				{
					if (xFin==8+80*3) xFin=8;
					else xFin+=80;
					curse.stop(); curse.play(false);
				}
				break;
			}
			case KEY_LEFT:
			{
				if (themode=="topmode")
				{
					if (xFin==8) xFin = 8+80*3;
					else xFin-=80;
					curse.stop(); curse.play(false);
				}
				break;
			}
			case KEY_DOWN:
			{
				if (themode=="equip" || themode=="remove")
				{
					if (yFin==82) yFin = 43;
					else yFin+=13;
					curse.stop(); curse.play(false);
				}
				else if (themode=="equip_sel")
					yFin += 13;
				break;
			}
			case KEY_UP:
			{
				if (themode=="equip" || themode=="remove")
				{
					if (yFin==43) yFin = 82;
					else yFin-=13;
					curse.stop(); curse.play(false);
				}
				else if (themode=="equip_sel")
					yFin -= 13;
				break;
			}
			case KEY_PAGEUP:
			{
				if (party.length>1)
				{
					curse.stop(); curse.play(false);
					if (fool == party.length-1){ equipmenu(0); return; }
					else { equipmenu(fool+1); return; }
				}
				break;
			}
			case KEY_PAGEDOWN:
			{
				if (party.length>1)
				{
					curse.stop(); curse.play(false);
					if (fool==0) {equipmenu(party.length-1); return; }
					else { equipmenu(fool-1); return; }
				}
				break;
			}
		}
		}
	}
}

function emptyequip(saki)
{
	charstats[party[saki]].rhand = undefined;
	charstats[party[saki]].lhand = undefined;
	charstats[party[saki]].head = undefined;
	charstats[party[saki]].body = undefined;
}


function shopmenu(somethin)
{
	window.drawWindow(0,0,320,240);
	alphagrad.blit(0,0);
	window2.drawWindow(7, 12, 308, 10);
	//window2.drawWindow(7, 20+30, 310, 10);
	window2.drawWindow(7, 65, 165, 160);
	window2.drawWindow(191, 65, 122, 160);
	FlipScreen();
	GetKey();
}
